package constant;import com.rabbitmq.client.Connection;import com.rabbitmq.client.ConnectionFactory;/** * @Auther: sky * @Date: 2019/3/18 23:55 * @Description:获取连接 */public class ConnectionUtils {    /**     * 获取连接     * @return Connection     * @throws Exception     */    public static Connection getConnection() throws Exception {        //定义连接工厂        ConnectionFactory factory = new ConnectionFactory();        factory.setHost("127.0.0.1");//        factory.setHost("192.168.1.104");        factory.setPort(5672);        //设置vhost        factory.setVirtualHost("/");        factory.setUsername("guest");        factory.setPassword("guest");        //通过工厂获取连接        Connection connection = factory.newConnection();        System.out.println(connection);        return connection;    }}